<?php

namespace app\common\logic;

use app\common\library\exception\ApiException;
use app\common\library\MemberVo;
use app\common\model\Banner;
use app\common\model\Car;
use app\common\model\CarImages;
use app\common\model\CarImagesShop;
use app\common\model\CarSeries;
use think\db\Query;


class BannerLogic extends BaseLogic
{
    public $model;


    public function assignModel()
    {
        $this->model               = new Banner();
    }

    /**
     * 搜索条件处理
     * @param Query $query
     * @param array $params
     * @return Query
     */
    public function handleSearch(Query $query, array $params): Query
    {
        if(isset($params['status']) && !empty($params['status'])) {
            $query->where('status', $params['status']);
        }

        $query->where('type', 'in',[0,1,2]);

        if(isset($params['id']) && !empty($params['id'])) {
//            halt(111);
            $query->where('id', $params['id']);
        }

        return $query;
    }

    public function index()
    {
        $params['status'] = 1;
        $params['orderBy'] = 'sort';
        $params['orderType'] = 'desc';
        $params['field'] = ['id','name','url','link_type','link','type','content'];
        return $this->getList($params);
    }

    /**轮播图详情
     * @param $params
     * @return \think\Model|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function banner_detail($params)
    {
        return $this->first(['id'=>$params['id']]);
    }

}